// 导入combineReducers
import { combineReducers } from 'redux';
// reducer函数: 根据actions返回最新的状态数据state
import { ADD_MESSAGE, DEL_MESSAGE, GET_MESSAGE, GET_SLIDER } from './action-types';
// 默认数据
// const initData=[{id:1,content:'寄意寒星荃不察,我以我血荐轩辕,横眉冷对千夫指,俯首甘为孺子牛',author:'鲁迅',createTime:new Date()}];
var initData = [];
const message = (state = initData, action) => {
    switch (action.type) {
        case ADD_MESSAGE:
            const arr = [...state];
            const id = state.length > 0 ? state[0].id + 1 : 1;
            arr.unshift({ id, ...action.data });
            return arr;
            break;
        case DEL_MESSAGE:
            return state.filter(item => item.id !== action.data);
            break;
        case GET_MESSAGE:
            return action.data;
            break;
        default:
            return state;
    }
}


// 轮播图数数据的reducer
const initSlider = [];
function slider(state = initSlider, action) {
    switch (action.type) {
        case GET_SLIDER:
            return action.data;
            break;
        default:
            return state;
    }
}

// 合并&导出reducer
export default combineReducers({ message,slider });